package com.example.wedding_mq.listener;

import com.zpp.wedding_admin.service.IGoodService;
import com.zpp.wedding_admin.service.IUserService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static com.zpp.wedding_admin.utils.RabbitConstants.*;
import static com.zpp.wedding_admin.utils.RabbitConstants.QUEUE_GOOD_ADD;

@Component
public class GoodListener {

    @Autowired
    private IUserService userService;

    @Autowired
    private IGoodService goodService;

    @RabbitListener(queues = QUEUE_GOOD_ADD)
    public void listenerGoodAdd(String[] ids) {
        String id = ids[0];
        String userId = ids[1];
        goodService.goodAdd(id, userId);
        userService.goodAdd(userId);
    }

    @RabbitListener(queues = QUEUE_GOOD_ADD)
    public void listenerGoodSubtract(String[] ids) {
        String id = ids[0];
        String userId = ids[1];
        goodService.goodSubtract(id, userId);
        userService.goodSubtract(userId);
    }
}
